import 'package:flutter/material.dart';
import 'package:flutter_reader/dao/bookinfo_data_manager.dart';
import 'package:flutter_reader/model/book/book_review_model.dart';
import 'package:flutter_reader/model/home/HotModel.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BookReviewPage extends StatefulWidget {
  BookReviewPage({Key key}) : super(key: key);

  @override
  _BookReviewPageState createState() {
    return _BookReviewPageState();
  }
}

class _BookReviewPageState extends State<BookReviewPage> {

  ///新增书评相关
  bool _isLoadingReview = true;
  List<Docs> _reviewDocs;


  loadBookReview()
  {
    BookDao.fetchBookReview().then((value){
      setState(() {
        _reviewDocs = value.docs;
        _isLoadingReview = false;
        debugPrint("书评加载已经结束");
      });
    });
  }

  @override
  void initState() {
    loadBookReview();
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("书籍评论"),
        actions: <Widget>[
          FlatButton(
            textColor: Colors.white,
            onPressed: () {},
            child: Text("写评论"),
            shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
          ),
        ],
      ),
      body: _isLoadingReview ? CircularProgressIndicator() : Container(
        child: Column(
            children: List.generate(_reviewDocs.length, (index) =>
                Container(
                  padding: EdgeInsets.only(left: ScreenUtil().setWidth(40), right: ScreenUtil().setWidth(40), top: ScreenUtil().setHeight(40)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                        child: Row(
                          children: <Widget>[
                            Container(
                              child: Icon(
                                  Icons.account_circle
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                              child: Text(
                                _reviewDocs[index].author.nickname,
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),

                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().setHeight(20)),
                        child: Text(_reviewDocs[index].content),
                      ),
                      Container(
                          margin: EdgeInsets.only(top: ScreenUtil().setHeight(20)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Icon(
                                    Icons.chat_bubble_outline,
                                    size: 20,
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                                    child: Text("评论"),
                                  )
                                ],
                              ),
                              Container(
                                margin: EdgeInsets.only(right: ScreenUtil().setWidth(40)),
                                child: Row(
                                  children: <Widget>[
                                    Image.asset("images/like.png",width: ScreenUtil().setWidth(44),),
                                    Container(
                                      margin: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                                      child: Text("点赞"),
                                    )

                                  ],
                                ),
                              )
                            ],
                          )
                      )
                    ],
                  ),
                ))
        ),
      ),
    );
  }
}